//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<string.h>
///	@path	~/src/lib/utilities/
///	@date	2007/06/17
///	@desc	strings in xeres.

#pragma once

#include "xeres.h"

// use STL's string as base
#include <string>
#include <deque>
#include <vector>

// widen string macro
#define __WIDE_STR(_String) L ## _String
#define _WIDE_STR(_String) __WIDE_STR(_String)

namespace xeres
{
	/// \brief Use STL's string as string representation.
	typedef std::string AString;

	/// \brief Use STL's string as string representation.
	typedef std::wstring WString;

	/*!
		\brief		Convert Unicode string to multi-byte string.
	*/
	static inline void wcs_to_mbs( const WString& src , AString& dst );

	/*!
		\brief		Convert Unicode string to multi-byte string.
	*/
	static inline void wcs_to_mbs( const wchar_t * src , AString& dst );

	/*!
		\brief		Convert multi-byte string to Unicode string.
	*/
	static inline void mbs_to_wcs( const AString& dst , WString& src );

	/*!
		\brief		Convert multi-byte string to Unicode string.
	*/
	static inline void mbs_to_wcs( const char * dst , WString& src );

	// string sequence
	typedef std::deque< WString >	StringSeq;

	/*!
		\brief		Break string into strings with separator.
	*/
	template< typename _STLString > static inline void break_string(
		const _STLString& str , const wchar_t seperator ,
		std::deque< _STLString >& result , bool invert_seq = false );

	/*!
		\brief		Encode string to UTF-8.
	*/
	static inline size_t encode_to_utf8( const wchar_t * src , size_t len , std::vector< byte >& dst );

	/*!
		\brief		Decode string from UTF-8.
	*/
	static inline size_t decode_from_utf8( const byte * src , size_t len , WString& dst );

	/*! 
		\brief		Fast ASCII to integer.
	*/
	static inline int xstrtoi( const wchar_t * str );

	/*! 
		\brief		Fast ASCII to integer.
	*/
	static inline int xstrtoi_scan( const wchar_t *& str );

	/*! 
		\brief		Fast ASCII to float.
	*/
	static inline double xstrtod( const wchar_t * str );

	/*! 
		\brief		Fast ASCII to float.
	*/
	static inline double xstrtod_scan( const wchar_t *& str );

} // namespace xeres

#include "lib/utilities/string.inl"
